﻿#include "C3fdPerformCurveDialog.h"
#include "ui_C3fdPerformCurveDialog.h"

namespace MainWidget {

	C3fdPerformCurveDialog::C3fdPerformCurveDialog(QWidget *parent)
		: QDialog(parent), m_Ui(new Ui::C3fdPerformCurveDialog)
	{
		m_Ui->setupUi(this);
		Qt::WindowFlags flags = Qt::Dialog;
		flags |= Qt::WindowCloseButtonHint;
		setWindowFlags(flags);

		m_Ui->lw_WorkingConditions->setDragDropMode(QAbstractItemView::InternalMove);
	}

	C3fdPerformCurveDialog::~C3fdPerformCurveDialog()
	{
		delete m_Ui;
	}

	void C3fdPerformCurveDialog::setItems(QStringList items)
	{
		m_Ui->lw_WorkingConditions->clear();
		for (auto name : items) {
			auto* item = new QListWidgetItem(name);
			item->setCheckState(Qt::CheckState::Unchecked);
			m_Ui->lw_WorkingConditions->addItem(item);
		}
	}


	void C3fdPerformCurveDialog::on_pb_Plot_clicked()
	{
		QStringList wcs = {};
		for (int i = 0; i < m_Ui->lw_WorkingConditions->count(); i++)
		{
			auto* item = m_Ui->lw_WorkingConditions->item(i);
			if (item->checkState() == Qt::CheckState::Checked) {
				wcs << item->text().simplified();
			}
		}
		if (wcs.size() > 0)
		{
			emit plotPerformCurveSig(wcs);
			QDialog::accept();
		}
	}

	void C3fdPerformCurveDialog::on_pb_Cancel_clicked()
	{
		QDialog::reject();
	}


}
